package cn.bdqn.layui.controller;

import cn.bdqn.layui.entity.PaymentRecord;
import cn.bdqn.layui.service.pay.PayService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PayController {

    @Resource
    PayService payService;

    @RequestMapping("/pay/userjiao")
    public String toPay() {
        return "/views/pay/pay";
    }

    @RequestMapping("/payall")
    @ResponseBody
    public String findPayAll(Integer page, Integer limit, String username, String propertyTypeName) {
        page = page == null ? 1 : page;
        limit = limit == null ? 10 : limit;
        int count = payService.findPayAllCount(username, propertyTypeName);
        List<PaymentRecord> payAll = payService.findPayAll(username, propertyTypeName, (page - 1) * limit, limit);
        JSONObject object = new JSONObject();
        object.put("code", 0);
        object.put("msg", "");
        object.put("data", payAll);
        object.put("count", count);
        return object.toJSONString();
    }
}
